<?php
namespace app\serverarticle\service\article;

use \app\manage\service\ApiBase;
use think\Validate;
/**
 * 文章类
 * @author  蒋哲
 * 验证：
添加或编辑时：
[不需要验证的字段:''默认值]   [需要验证但不require的:' '默认,使其验证]   [必须require的字段:无需默认值]
搜索时：
可空，给予''默认值，跳过验证器即搜索值为空时，不验证，不搜索
 * 编辑类，传什么验什么
 */
class ApiArticle extends ApiBase
{
    protected $addFields   = ["title"=>"", "classify_id"=>"", "content"=>"", "author"=>"", "order"=>0, "cover_id"=>0, "cover_absolute"=>"", "cover_relative"=>"", "writer_id"=>"",
        "nickname"=>" ", "keywords"=>" ", "description"=>" ", "shortname"=>" ", "top"=>0, "recommended"=>0, "status"=>1,
        "release_status"=>1, "arcrank"=>1, "review_status"=>1, "reprinted_status"=>1, "jump_url"=>" ", "source"=>" "];
    protected $articleValidate = 'app\serverarticle\validate\Article';
    protected $articleLogic    = '\app\serverarticle\logic\Article';

    // 文章发布
    public function add()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->haveIssetReceiveData($this->addFields);
        return $this->stepRun($data,'articleAdd','add',$this->articleValidate,$this->articleLogic);
    }

    // 文章编辑
    public function edit()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $default = array_merge($this->addFields,['id'=>""]);
        $data = $this->issetReceiveData($default);
        return $this->stepRun($data,'articleEdit','edit',$this->articleValidate,$this->articleLogic);
    }

    // 置顶某篇文章
    public function top()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'top','status',$this->articleValidate,$this->articleLogic);
    }

    // 取消置顶某篇文章
    public function cancelTop()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'cancelTop','status',$this->articleValidate,$this->articleLogic);
    }

    // 推荐某篇文章
    public function recommended()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'recommended','status',$this->articleValidate,$this->articleLogic);
    }

    // 取消推荐某篇文章
    public function cancelRecommended()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'cancelRecommended','status',$this->articleValidate,$this->articleLogic);
    }

    // 删除某篇文章
    public function delete()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'delete','status',$this->articleValidate,$this->articleLogic);
    }

    // 回复启用某篇文章
    public function enable()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'enable','status',$this->articleValidate,$this->articleLogic);
    }

    // 上架/重新发布某篇文章
    public function release()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'release','status',$this->articleValidate,$this->articleLogic);
    }

    // 下架某篇文章
    public function cancelRelease()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'cancelRelease','status',$this->articleValidate,$this->articleLogic);
    }

    // 阅读权限 仅自己可见
    public function oneselfVisible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'oneselfVisible','status',$this->articleValidate,$this->articleLogic);
    }

    // 阅读权限 所有人可见
    public function everyoneVisible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'everyoneVisible','status',$this->articleValidate,$this->articleLogic);
    }

    // 阅读权限 指定人可见
    public function nominatorVisible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'nominatorVisible','status',$this->articleValidate,$this->articleLogic);
    }

    // 阅读权限 指定人不可见
    public function nominatorInvisible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'nominatorInvisible','status',$this->articleValidate,$this->articleLogic);
    }

    // 评论权限 允许评论
    public function review()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'review','status',$this->articleValidate,$this->articleLogic);
    }

    // 评论权限 禁止评论
    public function banReview()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'banReview','status',$this->articleValidate,$this->articleLogic);
    }

    // 转载权限 允许转载
    public function reprinted()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'reprinted','status',$this->articleValidate,$this->articleLogic);
    }

    // 转载权限 禁止转载
    public function banReprinted()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'banReprinted','status',$this->articleValidate,$this->articleLogic);
    }

    // 审核通过
    public function audit()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'','audit_id'=>'']);
        return $this->stepRun($data,'audit','audit',$this->articleValidate,$this->articleLogic);
    }

    // 审核失败
    public function auditFailure()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'','audit_id'=>'']);
        return $this->stepRun($data,'auditFailure','audit',$this->articleValidate,$this->articleLogic);
    }

    // 指定文章可见人
    public function visible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'','visible'=>'']);
        if (count($data['visible']) > 10) {
            return auto_failure($this->arrData,"指定可见人人数不能超过10人！");
        }
        return $this->stepRun($data,'visible','status',$this->articleValidate,$this->articleLogic);
    }

    // 指定文章不可见人
    public function invisible()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'','invisible'=>'']);
        if (count($data['invisible']) > 10) {
            return auto_failure($this->arrData,"指定不可见人人数不能超过10人！");
        }
        return $this->stepRun($data,'invisible','status',$this->articleValidate,$this->articleLogic);
    }

    // 点赞 次数+1
    public function praise()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'praise','status',$this->articleValidate,$this->articleLogic);
    }

    // 踩 次数+1
    public function trample()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'trample','status',$this->articleValidate,$this->articleLogic);
    }

    // 点击/浏览 次数+1
    public function click()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'click','status',$this->articleValidate,$this->articleLogic);
    }

    // 评论条数 次数+1
    public function comments()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'comments','status',$this->articleValidate,$this->articleLogic);
    }

    // 转载次数 次数+1
    public function reprint()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['id'=>'']);
        return $this->stepRun($data,'reprint','status',$this->articleValidate,$this->articleLogic);
    }

    // 全部文章获取
    public function articleList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->haveIssetReceiveData(['listRows'=>15, 'page'=>1,'classify_id'=>'', 'keywords'=>'']);
        return $this->logic($this->articleLogic)->articleList($data);
    }

    // 前台 获取某一类文章列表 非删除 非置顶 非推荐 已发布 所有人可见 审核通过
    public function someList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['classify_id'=>'','listRows'=>15, 'page'=>1]);
        return $this->stepRun($data,'someList','list',$this->articleValidate,$this->articleLogic);
    }

    // 获取某一篇文章信息 非删除
    public function articleInfo()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->haveIssetReceiveData(['id'=>0]);
        return $this->stepRun($data,'articleInfo','status',$this->articleValidate,$this->articleLogic);
    }

    // 获取某一类置顶状态文章列表 非删除
    public function topList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['classify_id'=>'','listRows'=>15, 'page'=>1]);
        return $this->stepRun($data,'topList','list',$this->articleValidate,$this->articleLogic);
    }

    // 获取某一类推荐状态文章列表 非删除
    public function recommendedList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['classify_id'=>'','listRows'=>15, 'page'=>1]);
        return $this->stepRun($data,'recommendedList','list',$this->articleValidate,$this->articleLogic);
    }

    // 前台 获取某一类文章列表 非删除 已发布 所有人可见 审核通过
    public function allList()
    {
        if (empty($this->arrData)) {
            return null_data($this->arrData,"参数不能为空！");
        }
        $data = $this->receiveData(['classify_id'=>'','listRows'=>15, 'page'=>1]);
        return $this->stepRun($data,'allList','list',$this->articleValidate,$this->articleLogic);
    }
}
